package com.myacg.platform.ui.event.move;

import java.awt.Component;

import com.myacg.core.entity.Point;
import com.myacg.core.utils.MoveUtils;

/**
 * 回弹移动事件
 * @author Administrator
 *
 */
public class SpringbackMoveToEvent  extends BaseLineMoveToEvent{
	int backcount=0;
	public SpringbackMoveToEvent(Component comp) {
		super(comp);
	}

	@Override
	protected void OutOffByRunBefor() {
		System.out.println(movePlugin.getMoveLength());
		if(this.ismoveEnd()){
			this.moveEngine.pause();//超出距离就停止
		} 
	}
	
	@Override
	protected void OutOffByRunAfter() {
		// TODO Auto-generated method stub
		
	}
	/**
	 * 重写父类的moveTo方法
	 */
	@Override
	public void moveTo(Point endPoint, double F, double V0) {
		Point selfPoint = new Point(comp.getLocation().x, comp.getLocation().y);
		double direction = MoveUtils.getAngle(selfPoint, endPoint);
		this.endPoint=endPoint;
		 
		if(backcount>=1){
    	    //计算目标点和方向
        	//获取与目标点之间的差距
        	length=MoveUtils.getRangle(selfPoint, endPoint);
		}else{ //第一次回退
			this.initF=F;
			this.initV0=V0; 
			//改变相反的方向
			direction=-direction;
			//回弹的长度调整为十分之一
			length=MoveUtils.getRangle(selfPoint, endPoint)/10;
		}
        	//获取角度
        	if(length!=0){
        		//重设方向
        		movePlugin.setDirection(direction);
        		//重设引擎内核起始点
        		Point p =movePlugin.getPoint();
        		p.x=selfPoint.x;
        		p.y=selfPoint.y;
        		//重置运行状态
            	movePlugin.resetState();
            	//给予某个速度点
            	movePlugin.setF(F);
        		movePlugin.setV0(V0);
        		//启动
        		this.moveEngine.keep();
        		}
	 
	}
	//当被暂停时候
	protected void pauseStop() {
		super.pauseStop();
		System.out.println("停止");
		if(endPoint!=null ){
			backcount++;
		}
		if(backcount>=1){
			System.out.println("this.movePlugin.getF(): "+this.initF);
			moveTo(endPoint,Math.abs(this.initF),0);
			backcount=0;
		}
	}
	
}
